package com.yzdg.common.entitys;

import com.yzdg.common.enums.ErrorCode;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.UUID;

/**
 * 通用返回类
 */
@Data
@NoArgsConstructor
public class BaseResponse<T> implements Serializable {

    private boolean success = false;

    private int code;

    private T data;

    private String message;

    private String uuid = UUID.randomUUID().toString();

    private Long timestamp = System.currentTimeMillis();

    public BaseResponse(int code, T data, String message) {
        if (code == 0){
            this.success = true;
        }
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public BaseResponse(int code, T data) {
        if (code == 0){
            this.success = true;
        }
        this.code = code;
        this.data = data;
        this.message = "";
    }

    public BaseResponse(ErrorCode errorCode) {
        if (errorCode.getCode() == 0){
            this.success = true;
        }
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
    }
}
